from .exts import db

collect = db.Table('collects',
                   db.Column('id', db.Integer, primary_key=True, autoincrement=True),
                   db.Column('userid', db.Integer, db.ForeignKey('user_model.id')),
                   db.Column('movieid', db.Integer, db.ForeignKey('movie_model.id'))
                   )


class UserModel(db.Model):
    __tablename__ = 'user_model'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30))
    age = db.Column(db.Integer)


class MovieModel(db.Model):
    __tablename__ = 'movie_model'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(30))

    users = db.relationship('UserModel', backref='movies', lazy='dynamic', secondary=collect)
